<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<nav class="navbar navbar-inverse" role="navigation">
  <div class="container">
    <div class="navbar-header">
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
	              aria-expanded="false" aria-controls="navbar">
	        <span class="sr-only">Toggle navigation</span>
	        <span class="icon-bar"></span>
	        <span class="icon-bar"></span>
	        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" style="color:#fff;" href="${ctx}">FirstApp.Me</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse header-navbar">
        <form class="navbar-form navbar-left" role="search" action="${ctx}/search" method="get">
          <div class="form-group">
            <input id="keyword" name="keyword" type="text" class="form-control"  placeholder=" 搜索话题、商品">
          </div>
        </form>
        <ul class="nav navbar-nav">
        	<li class="<c:if test='${navFlag eq 0}'>active</c:if>"><a href="${ctx}"><span class="glyphicon glyphicon-list-alt"></span>&nbsp发现</a></li>
        	<li class="<c:if test='${navFlag eq 1}'>active</c:if>"><a href="${ctx}/topic/sections"><span class="glyphicon glyphicon-th-large"></span>&nbsp板块</a></li>
        	<li class="<c:if test='${navFlag eq 2}'>active</c:if>"><a href="${ctx}/shop/index"><span class="glyphicon glyphicon-shopping-cart"></span>&nbsp商店</a></li>
        </ul>
        
      <ul class="nav navbar-nav navbar-right">
        <c:if test="${member eq null}">
	        <li><a href="${ctx}/member/login?returnUrl=${pageUrl}">登录</a></li>
	        <li><a href="${ctx}/member/register?returnUrl=${pageUrl}">注册</a></li>
        </c:if>
        <c:if test="${member ne null}">
	        <li >
	            <p class="navbar-text">欢迎你,${member.name}！</p>
	        </li>
	        <li>
	        	<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
	              	消息
	              	<span id="notiTotalCounts" class="badge"></span>
	              	<span class="caret"></span>
	            </a>
	             <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuDivider">
	             	<li role="presentation">
	             		<a role="menuitem" tabindex="0" href="${ctx}/notification/bbsNotification">
	             			社区消息
	             			<span id="bbsNotiCounts" class="badge"></span>
	             		</a>
	             	</li>
	             	<li role="presentation" class="divider"></li>
	             	<li role="presentation">
	             		<a role="menuitem" tabindex="1" href="${ctx}/notification/shopNotification">
	             			店铺消息
	             			<span id="shopNotiCounts" class="badge"></span>
	             		</a>
	             	</li>
	             	<li role="presentation" class="divider"></li>
	             	<li role="presentation">
	             		<a role="menuitem" tabindex="2" href="${ctx}/notification/systemNotification">
	             			系统消息
	             			<span id="sysNotiCounts" class="badge"></span>
	             		</a>
	             	</li>
	             </ul>
	        </li>
        </c:if>
        <c:if test="${member ne null}">
	        <li>
	            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
	              		设置
	              <span class="caret"></span>
	            </a>
	            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuDivider">
	              <li><a role="menuitem" tabindex="0" href="${ctx}/memberCenter/profile">个人主页</a></li>
	              <li role="presentation" class="divider"></li>
	              <li><a role="menuitem" tabindex="1" href="${ctx}/member/logout">退出登录</a></li>
	            </ul>
	        </li>
        </c:if>
      </ul>
    </div>
  </div>
  <input id="loginMemberId" type="hidden" value="${member.id}">
</nav>
<script type="text/javascript">
	$(document).ready(function(){
		var memberId = $("#loginMemberId").val();
		if(memberId != null){
			$.ajax({
				type : 'GET',
				url : ctx + '/getNotification.do',
				data : {
					
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					if (data.code == "ok") {
						var notification = data.object;
						var bbsCounts = notification.bbs;
						var shopCounts = notification.shop;
						var systemCounts = notification.system;
						var bbsCountsInt = parseInt(bbsCounts);
						var shopCountsInt = parseInt(shopCounts);
						var systemCountsInt = parseInt(systemCounts);
						if(bbsCountsInt > 0){
							$("#bbsNotiCounts").html(bbsCounts);
						}
						if(shopCountsInt > 0){
							$("#shopNotiCounts").html(shopCounts);
						}
						if(systemCountsInt > 0){
							$("#sysNotiCounts").html(systemCounts);
						}
						var totalCounts = bbsCountsInt + shopCountsInt + systemCountsInt;
						if(totalCounts > 0){
							$("#notiTotalCounts").html(totalCounts);
						}
					} else {
						console.log(data.msg);
					}
				},
				error : function(xhr, type) {
					console.log('消息查詢接口提交失败!');
				}
			});
		}
	});
</script>
<script type="text/javascript">
/*  	function search(){
 		var keyword = $("#keyword").val();
 		window.location.href = decodeURIComponent(ctx + '/search?keyword=' + keyword );
 	} */
</script>